import React, { Component } from 'react';
import { Select, Input, Button, Modal, message } from 'antd';
const Option = Select.Option;
import axios from 'axios';
import './index.less';

class DetailsModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      id: '',
      data: [],
      show: '',
      unApprove: ''
    };
  }

  componentWillReceiveProps(nextProps) {
    if (this.state.id == nextProps.ID) {
      return false;
    } else {
      this.state.id = nextProps.ID;
      this.state.unApprove = nextProps.unApprove;
      this.state.show = nextProps.show;
      this.getData(nextProps.ID, nextProps.unApprove);
    }
  }

    getData = (id) => {
      let oUrl = '';
      if (this.state.unApprove) {
        oUrl = 'api/admin/approve/unApproveOrg/';
      } else {
        oUrl = '/api/admin/approve/org/';
      }
      const Token = sessionStorage.getItem('token');
      const _this = this;
      axios({
        method: 'get',
        url: oUrl + id,
        headers: {
          Authorization: Token
        }
      })
        .then(function (response) {
          if (_this.state.unApprove) {
            _this.setState({
              data: response.data.data
            });
          } else {
            _this.setState({
              data: response.data
            });
          }
        })
        .catch(function (error) {
          console.log(error);
          message.error('服务器开小差啦，请重试！');
        });
    }

    show = () => {
      this.setState({
        show: true
      });
    }

    render() {
      const { visible, onCancel, onCreate } = this.props;
      return (
        <Modal
          visible={visible}
          title="查看"
          okText="确定"
          cancelText="取消"
          onCancel={onCancel}
          onOk={onCreate}
        >
          <div>
            <p>id： {this.state.data.id}</p>
            <p>批准时间： {this.state.data.approvalTime}</p>
            <p>申请时间： {this.state.data.crtTime}</p>
            <p>邮箱： {this.state.data.email}</p>
            <p>法人： {this.state.data.legalPerson}</p>
            <p>组织地址： {this.state.data.orgAddress}</p>
            <p>组织名称： {this.state.data.orgName}</p>
            <p>手机号码： {this.state.data.phone}</p>
            <p>姓名： {this.state.data.realname}</p>
            {/* <p>申请理由： {this.state.data.remark}</p> */}
            {
              this.state.data.status == 1 ? <p>状态： 通过</p> : ''
            }
            {
              this.state.data.status == 0 ? <p>状态： 审核中</p> : ''
            }
            {
              this.state.data.status == -1 ? <p>状态： 拒绝</p> : ''
            }
            <p>
                        营业执照：
              <span className="businesslicenseBox" onClick={this.show}>
                <img src={this.state.data.businesslicense} className={this.state.show ? 'businesslicenseFixed' : 'businesslicense'} />
              </span>
            </p>
          </div>
        </Modal>
      );
    }

}

export default DetailsModal;